var htmlCodes = [
    '  <div>',
    '        <el-tree :data="data" :props="defaultProps"  @node-click="handleNodeClick"></el-tree>',
    '   </div>'
].join("");

Vue.component('zy-category-tree', {
    template:htmlCodes,
    props: {
        treeData: {},
        treeUrl: null,
        defineProps: null,
    },
    data() {
        return {
            data:{},
            defaultProps: {
                children: 'children',
                label: 'label'
            },
        }
    },
    mounted: function () {
        this.initData();
    },
    methods: {
        initData: function () {
            if(this.$props.defineProps){
                this.defaultProps = this.$props.defineProps;
            }
            //1. 优先取 TreeData
            if (!this.$props.treeData && !this.$props.treeUrl){
                alert("请传入数据来源!");
                return;
            }
            if (this.$props.treeData){
                this.data = this.$props.treeData;
                return;
            }
            if (this.$props.treeUrl){
                var self = this;
                $.get(baseURL + this.$props.treeUrl, function(r){
                    if(r.code == 0){
                        self.data = r.treeData
                    }else{
                        alert(r.msg);
                    }
                });
                return;
            }

        },

        handleNodeClick: function (data) {
            console.log(data);
            this.$emit('node-click', data)
        },
    },
});

